<template>
	<view>
		<view>
			<view>
				<view class="header">
					<!-- <image src="/static/images/logo.png"></image> -->
					</view>
				<view class="content">
				<!-- 	<view>申请获取以下权限</view>
					<text>获得你的公开信息(手机号、昵称、头像等)</text> -->
					<text>请选择您的身份</text>
				</view>
				<view class="choose userpic" v-show="a==0" @click="choose(1,0)"></view>
				<view class="choose userpicSelect" v-show="b==0" @click="choose(1,0)"></view>
				<view class="choose orgpic" v-show="a==1" @click="choose(0,1)"></view>
				<view class="choose orgpicSelect" v-show="b==1" @click="choose(0,1)"></view>
				<!-- <button v-show="!after" open-type="getUserInfo" @getuserinfo="getuserinfo">点击授权</button> -->
				<button  class="page_btn" hover-class="page_btn-hover" @tap="getPhoneOneClickUser">确定</button>
				
			</view>
		</view>
	</view>
</template>
<script>
	import {
		HTTP_SERVER_URL,
		STATUS_CODE
	} from '../../config/index.js';
export default {
	data() {
		return {
			code:null,
			img:null,
			name:null,
			after:false,
			a:0,
			b:1,
			trueUserDate:{
				age: null,
				id: 6,
				instituteId: null,
				isUser: 1,
				juzhudi: null,
				jwt: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJ7XCJ1c2VySWRcIjo2LFwidXNlclR5cGVcIjoxfSJ9.ILaqq32o5ZVeFxE5lN7Qs9qLV1yjflbH1PxsLdShmSQ',
				openId: 'sf12df54sd56fsd32fds2f1',
				owner: 1,
				phone: '',
				sex: null,
				shequ: null,
				userType: 1,
				username: null,
				wxAvatar: '',
				wxNickname: ''
			},
			userData:{
				age: null,
				id: 3,
				instituteId: null,
				isUser: 1,
				juzhudi: '大曌',
				jwt: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJ7XCJ1c2VySWRcIjozLFwidXNlclR5cGVcIjowfSJ9.h8FMVW7sVEYQYW-XKi01i7EMQ1Ea0qwtiJFnqc1Hub8',
				openId: 'sf12df54sd56fsd32fds2f1',
				owner: null,
				phone: '',
				sex: 1,
				shequ: null,
				userType: 0,
				username: null,
				wxAvatar: '',
				wxNickname: ''
			},
			orgData:{
				age: null,
				id: 6,
				instituteId: null,
				isUser: 1,
				juzhudi: null,
				jwt: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJ7XCJ1c2VySWRcIjo2LFwidXNlclR5cGVcIjoxfSJ9.ILaqq32o5ZVeFxE5lN7Qs9qLV1yjflbH1PxsLdShmSQ',
				openId: '',
				owner: 1,
				phone: '18813022201',
				sex: null,
				shequ: null,
				userType: 1,
				username: null,
				wxAvatar: '',
				wxNickname: ''
			}
		};
	},
	onBackPress() {
		if (this.defaultButton != 'back') {
			return true;
		}
	},
	onShow() {
		// let user=uni.getStorageSync('open')
		// if(user.jwt!=''){
		// 	uni.switchTab({
		// 		url:'../index/index'
		// 	})
		// }
	},
	methods: {
		choose(a,b){
			this.a=a
			this.b=b
			if(a==1){
				this.trueUserDate=this.userData
			}else if(a==0){
				this.trueUserDate=this.orgData
			}
			console.log(this.trueUserDate.wxNickname)
		},
		getuserinfo: function (e) {//用户登陆操作
		    // console.log(e.detail.userInfo.avatarUrl)
		    let that = this;
		    uni.login({
		      provider: 'weixin',
		     success:(res)=>{
		      console.log(res,'66666666666')
		      uni.setStorageSync('user', e.detail.userInfo);
		      // uni.setStorageSync('userName', e.detail.userInfo.nickName);
		      that.code=res.code//获取用户code
			  that.img=e.detail.userInfo.avatarUrl;
			  that.name=e.detail.userInfo.nickName
			  // console.log(e.detail.userInfo.avatarUrl);
			  that.after=true
			  // console.log(e.detail.userInfo.nickName);
			  console.log(that.code);
		      uni.request({
		      	url:HTTP_SERVER_URL+'/aged/user/appletsLogin',
				method:"POST",
				data:{
					code:that.code
				},
				success:(res)=>{
					console.log(res)
				}
		      })
		      }
		    });
		   },
		getPhoneOneClickUser() {
			let a=uni.getStorageSync('open')
			if(a.wxNickname){
				console.log('用户信息',a)
				this.$store.dispatch('wechatLogin', a).then(res => {
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/index/index'
						});
					}, 1100);
				});
				console.log('真登录')
			}else{
				uni.setStorageSync('open',this.trueUserDate)
				this.$store.dispatch('wechatLogin', this.trueUserDate).then(res => {
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/index/index'
						});
					}, 1100);
				});
				console.log('假登录')
			}
			
			
		},
		
	}
};
</script>

<style lang="stylus">
.choose
	width 90%
	margin 50rpx auto
	height 240rpx
	border-radius 50rpx
	box-shadow: 0px 10px 13px 2px rgba(254, 127, 39, 0.25)
	
	
	
	
.orgpicSelect
	background url(https://images-vx.oss-cn-beijing.aliyuncs.com/images-vx/org.png)
	background-size 100% 100%
.orgpic
	background url(https://images-vx.oss-cn-beijing.aliyuncs.com/images-vx/fuwufang.png)
	background-size 100% 100%
.userpic
	background url(https://images-vx.oss-cn-beijing.aliyuncs.com/images-vx/xuqiufang.png)
	background-size 100% 100%
.userpicSelect
	background url(https://images-vx.oss-cn-beijing.aliyuncs.com/images-vx/uesr.png)
	background-size 100% 100%
.header
	margin 110rpx 0 90rpx 50rpx
	// border-bottom 1px solid #ccc
	text-align center
	width 650rpx
	height 100rpx
	line-height 450rpx
.header image
	width 200rpx
	height 200rpx
.content
	// margin-left 50rpx
	
.content text
	display block
	color #9d9d9d
	margin-top 0rpx
	margin-bottom 140rpx
	font-size 48rpx
	margin-left 5%
.page_btn-hover
	opacity 0.5
.page_btn
	flex 1
	margin 170rpx 50rpx
	height 90rpx
	display flex
	align-items center
	justify-content center
	background #FF7D21
	border-radius 80rpx
	font-size 32rpx
	font-family PingFang SC
	font-weight 400
	color #FFFFFF
	border none
	outline none
	&:nth-of-type(2)
		margin-left 45rpx
</style>
